<?php
/**
 * Created by PhpStorm.
 * User: zhangxilu
 * Date: 2017/12/19
 * Time: 下午11:24
 */

namespace common\logic;


use common\models\AuthRuleModel;
use yii\db\ActiveQuery;

class MenuLogic extends Logic
{

    /**
     * @return ActiveQuery
     */
    protected function _getActiveQuery()
    {
        return AuthRuleModel::find();
    }

    /**
     * 获取所有排序过的菜单
     *
     * @return array|AuthRuleModel[]
     */
    public function getBySort(){
        return $this ->_all(['status'=>1], [], [], ['order' => SORT_ASC]);
    }

    /**
     * @param $id
     * @return array|null|\yii\db\ActiveRecord
     */
    public function getById($id){
        return $this->_get(['id' => $id]);
    }

    /**
     * 查询所有
     *
     * @param array $ids
     * @return array|AuthRuleModel[]
     */
    public function getAll($ids = [])
    {
        $where = [];
        if (!empty($ids)) {
            $where = ['id' => $ids,'status' => 1];
        }
        $where['status'] = 1;
        return $this->_all($where,[],[],['order'=>SORT_ASC]);
    }
	
	
	public function getPidAll($ids)
    {
        $where = ['pid' => $ids,'status' => 1];
        $where['status'] = 1;
        return $this->_all($where,[],[],['order'=>SORT_ASC]);
    }

    /**
     * 跟据连接获取菜单详细
     * @param $route
     * @return array|null|\yii\db\ActiveRecord
     */
    public function getByRoute($route){
        return $this->_get(['route' => $route]);
    }


}